<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="app">
      <ul>
        <li><router-link to="/">Home</router-link></li>
        <li><router-link to="/about">About</router-link></li>
      </ul>
      <keep-alive>
        <router-view></router-view>
      </keep-alive>
    </div>
    <script src="vue.js"></script>
    <script src="vue-router.js"></script>
    <script>
      const Home = {
        template: `<div>Home</div>`,
      };
      const About = {
        template: `<div>
          About
          <input/>
          </div>`,
          activated(){
            console.log('About组件被激活')
          },
          deactivated(){
            console.log('About组件失活')
          }
      };
      const routes = [
        { 
          name: "home", 
          path: "/", 
          component: Home 
        },
        { 
          name: "about", 
          path: "/about", 
          component: About 
        }
      ];

      var router = new VueRouter({
        routes,
      });
      var vm = new Vue({
        el: "#app",
        router,
      });
    </script>
  </body>
</html>
